package DemoText;

import java.util.Scanner;

/**
 * 最优包含
 */
public class LuoGuP8703 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        String t = in.nextLine();
        int n = minModify(s, t);
        System.out.println(n);
    }

    private static int minModify(String s, String p) {
        char[] arrs = s.toCharArray();
        char[] arrp = p.toCharArray();
        int ns = arrs.length, np = arrp.length;
        int[] hashs = new int[126];
        int[] hashp = new int[126];
        int min_len = Integer.MAX_VALUE;
        for (int i = 0; i < np; i++) hashp[arrp[i]]++;
        for (int left = 0, right = 0, k = 0; right < ns; right++) {
            int len = right - left + 1;
            hashs[arrs[right]]++;
            if (hashs[arrs[right]] <= hashp[arrs[right]]) k++;
            if (len > np) {
                if (hashs[arrs[left]] <= hashp[arrs[left]]) k--;
                hashs[arrs[left++]]--;
            }
            if (len == np) min_len = Math.min(min_len, np - k);
        }
        return min_len;
    }
}
